package com.zw.mizhe.view.adapter;

import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentPagerAdapter;

import com.zw.mizhe.bean.HomeBean;

import java.util.List;


/**
 * Created by zhangwei on 16/10/22.
 */

public class HomePagerAdapter extends FragmentPagerAdapter {
    private List<Fragment> fragments;

    private List<HomeBean> titles;


    public HomePagerAdapter(FragmentManager fm, List<Fragment> fragments) {
        super(fm);
        this.fragments = fragments;
    }

    public HomePagerAdapter(FragmentManager fm, List<Fragment> fragments, List<HomeBean> titles) {
        super(fm);
        this.fragments = fragments;
        this.titles = titles;
    }

    @Override
    public Fragment getItem(int position) {
        return fragments.get(position);
    }

    @Override
    public int getCount() {
        return fragments != null ? fragments.size() : 0;
    }

    @Override
    public CharSequence getPageTitle(int position) {
        return titles != null && !titles.isEmpty() ? titles.get(position).getName() : super.getPageTitle(position);
    }
}
